import { ProFormRadio } from '@ant-design/pro-components';
import { type ProFormRadioGroupProps } from '@ant-design/pro-form/lib/components/Radio';

const CommonFormRadio: React.FC<ProFormRadioGroupProps> = ({ required, rules = [], ...props }) => {
  return (
    <ProFormRadio.Group
      {...props}
      fieldProps={{
        buttonStyle: 'solid',
      }}
      rules={
        rules.some((rule) => 'required' in rule)
          ? rules
          : [
              {
                required,
                message: `请选择${props.label}`,
              },
              ...rules,
            ]
      }
    />
  );
};

CommonFormRadio.defaultProps = {
  required: false,
  placeholder: '',
  options: [
    { label: '是', value: 1 },
    { label: '否', value: 0 },
  ],
};

export default CommonFormRadio;
